/**
 * @param {number} n
 * @return {number}
*/
var subtractProductAndSum = function(n) {
  let strArr = n.toString().split(""), addRes = 0, mulRes = 1;
  for(let i = 0; i < strArr.length; i++) {
    addRes = addRes + parseInt(strArr[i]);
    mulRes = mulRes * parseInt(strArr[i]);
  }
  return mulRes - addRes;
};
let n = 234;
console.log(subtractProductAndSum(n));
n = 4421;
console.log(subtractProductAndSum(n));
